import base64
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from io import BytesIO

def wraper_fig(fig: Figure) -> str:
    fig.tight_layout(rect=[0, 0.1, 1, 0.95]) 
    buf = BytesIO()
    fig.savefig(buf, format='png', bbox_inches='tight')
    plt.close(fig)
    buf.seek(0)
    return f'data:image/png;base64,{base64.b64encode(buf.read()).decode()}'